/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FormularioReserva.java
 *
 * Created on 23/06/2010, 09:37:26 PM
 */

package CapaGrafica;
import CapaDatos.Fecha;
import javax.swing.JOptionPane;
import CapaLogica.ComunicacionServidor;

/**
 *
 * @author Maria
 */
public class FormularioReserva extends javax.swing.JFrame {
private MenuUsuario ventanaMadre;
    private String nombre;
    private String cedula;
    private Fecha hoy;
    private Fecha mañana;

    /** Creates new form FormularioReserva */
    public FormularioReserva(MenuUsuario ventana, String nombre, String cedula) {
        long dia = 86400000; //milisegundos

        ventanaMadre = ventana;
        this.nombre = nombre;
        this.cedula = cedula;
        hoy    = new Fecha();
        mañana = new Fecha();
        mañana.setTimeInMillis(hoy.getTimeInMillis() + dia);
        initComponents();
        jDCfechaIngreso.setMinSelectableDate(hoy.getTime());
        jDCfechaEgreso.setMinSelectableDate(mañana.getTime());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jBingresar = new javax.swing.JButton();
        jBcancelar = new javax.swing.JButton();
        jLfechaIngreso = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLhabitacion = new javax.swing.JLabel();
        jLformaDePago = new javax.swing.JLabel();
        jCBformaDePago = new javax.swing.JComboBox();
        jTFhabitacion = new javax.swing.JTextField();
        jDCfechaIngreso = new com.toedter.calendar.JDateChooser();
        jDCfechaEgreso = new com.toedter.calendar.JDateChooser();
        jSeparator1 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        setLocationByPlatform(true);

        jBingresar.setText("Ingresar");
        jBingresar.setName("jBingresar"); // NOI18N
        jBingresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBingresarActionPerformed(evt);
            }
        });

        jBcancelar.setText("Cancelar");
        jBcancelar.setName("jBcancelar"); // NOI18N
        jBcancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBcancelarActionPerformed(evt);
            }
        });

        jLfechaIngreso.setText("Fecha entrada:");
        jLfechaIngreso.setName("jLfechaIngreso"); // NOI18N

        jLabel1.setText("Fecha salida:");
        jLabel1.setName("jLabel1"); // NOI18N

        jLhabitacion.setText("Habitacion:");
        jLhabitacion.setName("jLhabitacion"); // NOI18N

        jLformaDePago.setText("Forma de pago:");
        jLformaDePago.setName("jLformaDePago"); // NOI18N

        jCBformaDePago.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "<Seleccione>", "Cheque", "Tarjeta de Credito", "Tarjeta de Debito" }));
        jCBformaDePago.setName("jCBformaDePago"); // NOI18N

        jTFhabitacion.setName("jTFhabitacion"); // NOI18N

        jDCfechaIngreso.setName("jDCfechaIngreso"); // NOI18N

        jDCfechaEgreso.setName("jDCfechaEgreso"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(59, 59, 59)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLfechaIngreso)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLhabitacion)
                        .addContainerGap())
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLformaDePago)
                            .addContainerGap())
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(jBingresar)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 129, Short.MAX_VALUE)
                                    .addComponent(jBcancelar))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(jLabel1)
                                    .addGap(66, 66, 66)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jCBformaDePago, 0, 148, Short.MAX_VALUE)
                                        .addComponent(jTFhabitacion, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
                                        .addComponent(jDCfechaEgreso, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
                                        .addComponent(jDCfechaIngreso, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE))))
                            .addGap(64, 64, 64)))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLfechaIngreso)
                    .addComponent(jDCfechaIngreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jDCfechaEgreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLhabitacion)
                    .addComponent(jTFhabitacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLformaDePago)
                    .addComponent(jCBformaDePago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 55, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBingresar)
                    .addComponent(jBcancelar))
                .addGap(31, 31, 31))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBingresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBingresarActionPerformed
     String errorFormaDePago = "Debe especificar la forma de pago a usar para poder reservar la habitación";
        String formaDePago = (String) jCBformaDePago.getSelectedItem();

        Fecha fechaIngreso = new Fecha();
        Fecha fechaEgreso  = new Fecha();

        fechaIngreso.setTime(jDCfechaIngreso.getDate());
        fechaEgreso.setTime (jDCfechaEgreso.getDate());

        if (!formaDePago.equals("< Seleccionar >"))
        {
            String mensaje = ComunicacionServidor.realizarReservacion
            (
                fechaIngreso.toString(),
                fechaEgreso.toString(),
                hoy.toString(),
                jTFhabitacion.getText(),
                ventanaMadre.getCedulaCliente()
            );

            String mensajes[] = mensaje.split(":");
            if (mensajes[0].equals("TRUE"))
            {
                AgregarAcompanante ventana = new AgregarAcompanante(ventanaMadre, nombre, cedula, mensajes[1], formaDePago, hoy.toString());
                this.setVisible(false);
                ventana.setVisible(true);
                this.dispose();
            }
            else
                JOptionPane.showMessageDialog(this, mensajes[1]);
        }
        else
        {
            JOptionPane.showMessageDialog(this, errorFormaDePago);
        }   // TODO add your handling code here:
    }//GEN-LAST:event_jBingresarActionPerformed

    private void jBcancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBcancelarActionPerformed
        ventanaMadre.setVisible(true);
        this.dispose();// TODO add your handling code here:
    }//GEN-LAST:event_jBcancelarActionPerformed

    /**
    * @param args the command line arguments
    */
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBcancelar;
    private javax.swing.JButton jBingresar;
    private javax.swing.JComboBox jCBformaDePago;
    private com.toedter.calendar.JDateChooser jDCfechaEgreso;
    private com.toedter.calendar.JDateChooser jDCfechaIngreso;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLfechaIngreso;
    private javax.swing.JLabel jLformaDePago;
    private javax.swing.JLabel jLhabitacion;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField jTFhabitacion;
    // End of variables declaration//GEN-END:variables

}
